<?php

class video {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty,$page='',$cat='',$product='') {
		$this->db = $db;
		$this->smarty = $smarty;
		$this->page = $page;
		$this->cat = $cat;
		$this->product = $product;
	}
	
	public function main() {
		Zend_Loader::loadClass('Zend_Gdata');
		Zend_Loader::loadClass('Zend_Gdata_YouTube');
		Zend_Loader::loadClass('Zend_Gdata_AuthSub');
		Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 
	
		$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
		$httpClient = 
			  Zend_Gdata_ClientLogin::getHttpClient(
						$username = GUSER,
								  $password = GPASS,
						  $service = 'youtube',
						  $client = null,
						  $source = 'MySource', // a short string identifying your application
						  $loginToken = null,
						  $loginCaptcha = null,
						  $authenticationURL);


	    $yt = new Zend_Gdata_YouTube($httpClient);
		$videoFeed = $yt->getUserUploads('LCS1908');
		$listvideo = array();
		$dem = 0;
		$id ='';
		$fid ='';
		foreach ($videoFeed as $entry) {
			
			$videoId = $entry->getVideoId();
			$listvideo[$dem]['link'] = $entry->getLink('alternate')->getHref();
				$listvideo[$dem]['src'] = $entry->mediaGroup->thumbnail[0]->url;
				$listvideo[$dem]['title'] = $entry->mediaGroup->title;
				$listvideo[$dem]['id'] = $videoId;
				//echo $dem;
		//	echo '<a href="'.$entry->getLink('alternate')->getHref().'" > <img src="' . $entry->mediaGroup->thumbnail[0]->url . '"';
		//	echo 'width="80" height="72" onclick="ytvbp.presentVideo(\'' . $videoId . '\')"> </a>';
		 	if($dem == 0)
				$fid =$videoId;
			$dem++;
		}
		if($this->cat==''){
			 $id = $fid;
		}else{
			 $id = $this->cat;
		}
		$this->smarty->assign('VIDEO',$id );
		$this->smarty->assign('LISTVIDEOS',$listvideo);
		$this->smarty->display("video.tpl");	
	}
	
	
	
}
?>
